<!DOCTYPE html>
<html>
<body>
  <div class="app">
    <div class="container">
      <h1>Selecto test</h1>
      <p class="description">For big array, selecto works slowly.</p>
      <div></div>
      <div class="table-scroll">
        <table class="main-table">
          <thead></thead>
          <tbody class="table-body"></tbody>
        </table>
      </div>
    </div>
  </div>
</body>
<style>
  .table-scroll {
    position: relative;
    width: 100%;
    z-index: 1;
    margin: auto;
    overflow: auto;
    height: 400px;
  }

  .table-scroll table {
    width: 100%;
    min-width: 1280px;
    margin: auto;
    border-collapse: separate;
    border-spacing: 0;
  }

  .table-wrap {
    position: relative;
  }

  .table-scroll th,
  .table-scroll td {
    padding: 3px;
    border: 1px solid #000;
    background: #fff;
    text-align: center;
    width: 30px;
    height: 30px;
    vertical-align: middle;
  }

  .table-scroll td div {
    width: 100%;
    height: 100%;
  }

  .table-scroll th {
    user-select: none;
  }

  .table-scroll thead th {
    background: #333;
    color: #fff;
    position: sticky;
    top: 0;
  }

  th:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #ccc;
  }

  thead th:first-child {
    z-index: 5;
  }

  .selected {
    background-color: #03C0C1;
  }
</style>
<script src="../../dist/selecto.js"></script>

<script>
  const theadElement = document.querySelector("thead");
  const tbodyElement = document.querySelector("tbody");
  const head = [];
  const body = [];
  head.push(`<th></th>`);

  for (let i = 0; i < 130; ++i) {
    head.push(`<th>Column ${i}</th>`);

    const tr = [];

    tr.push(`<th>Row ${i}</th>`);
    for (let j = 0; j < 130; ++j) {
      tr.push(`<td><div class="markable-cell">${j}</div></td>`);
    }
    body.push(`<tr>${tr.join("")}</tr>`);
  }

  theadElement.innerHTML = `<tr>${head.join("")}</tr>`;
  tbodyElement.innerHTML = body.join("");

  const selecto = new Selecto({
    container: document.body,
    selectableTargets: [".table-body .markable-cell"],
    hitRate: 0,
    continueSelect: true,
    selectFromInside: true,
    selectByClick: false,
  }).on("select", e => {
    e.added.forEach((el) => {
      el.classList.add("selected");
    });
    e.removed.forEach((el) => {
      el.classList.remove("selected");
    });
  });
</script>

</html>